package container

import "fmt"

func Del(slice []int, index int) []int {
	len1 := len(slice)
	if index < 0 || index >= len1 {
		return slice
	}

	var s1 []int
	s1 = append(s1, slice[:index]...)
	s1 = append(s1, slice[index+1:]...)
	return s1
}

func DelValue(slice []int, value int) []int {
	index := -1
	for i, v := range slice {
		if v == value {
			index = i
		}
	}

	if index >= 0 {
		return Del(slice, index)
	}

	return slice
}

func TestSlice() {

	var a []string
	var b = []string{}

	var c = []bool{true, false}

	fmt.Println(a)
	fmt.Println(b)
	fmt.Println(c)

	fmt.Println(a == nil)
	fmt.Println(b == nil)
	fmt.Println(c == nil)

	fmt.Println(len(c), cap(c))
	fmt.Println(len(a), cap(a))

	a = append(a, "1")
	fmt.Println(len(a), cap(a))

	a = append(a, "1")
	fmt.Println(len(a), cap(a))

	a = append(a, "1")
	fmt.Println(len(a), cap(a))

	fmt.Println(a)

	d := []int{1, 2, 3, 4, 5}
	e := d[:4]
	f := d[1:]

	fmt.Println(e)
	fmt.Println(f)

	d = make([]int, 2, 10)
	fmt.Println(d)

	var i []int
	fmt.Println(i == nil)
	fmt.Println(len(i))

	s1 := make([]int, 3) //[0 0 0]
	s2 := s1             //将s1直接赋值给s2，s1和s2共用一个底层数组
	s2[0] = 100
	fmt.Println(s1) //[100 0 0]
	fmt.Println(s2) //[100 0 0]

	s := []int{1, 3, 5}

	for i := 0; i < len(s); i++ {
		fmt.Println(i, s[i])
	}

	for _, value := range s {
		fmt.Println(value)
	}

	var s3 []int
	s3 = append(s3, 1)       // [1]
	s3 = append(s3, 2, 3, 4) // [1 2 3 4]
	s4 := []int{5, 6, 7}

	s4 = append(s3, s4...)
	fmt.Println(s3)
	fmt.Println(s4)

	a1 := []int{12, 2, 3}
	a2 := make([]int, 3)
	copy(a2, a1)

	a2[0] = 1
	fmt.Println(a1)
	fmt.Println(a2)
}
